package com.jsm.tf.net.protocol.serialize;

import com.alibaba.fastjson.JSON;

import java.io.IOException;
import java.nio.charset.Charset;

public class JsonSerializer implements Serializer {
    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
        return JSON.parseObject(bytes, clazz);
    }

    @Override
    public <T> byte[] serialize(T object) throws IOException {
        return JSON.toJSONString(object).getBytes(Charset.defaultCharset());
    }
}
